﻿namespace umbraco.DataServices.Linq {

    public struct PropertyIdentifier {

        private readonly int _documentType;
        private readonly string _propertyAlias;

        public PropertyIdentifier(int documentType, string propertyAlias) : this() {
            _documentType = documentType;
            _propertyAlias = propertyAlias;
        }

        public PropertyIdentifier(string propertyAlias) : this() {
            _propertyAlias = propertyAlias;
        }

        public int DocumentTypeId { get { return _documentType; } }
        public string PropertyAlias { get { return _propertyAlias; } }

        public override string ToString() {
            return DocumentTypeId + "." + PropertyAlias;
        }

        public override bool Equals(object obj) {
            if (obj is PropertyIdentifier) {
                var ident = (PropertyIdentifier)obj;
                if (ident.DocumentTypeId == DocumentTypeId && ident.PropertyAlias == PropertyAlias)
                    return true;
            }
            return false;
        }

        public override int GetHashCode() {
            return DocumentTypeId.GetHashCode() ^ PropertyAlias.GetHashCode();
        }

    }
}
